package com.miyang.service;

import com.miyang.dao.UserDao;
import com.miyang.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shijin.huang
 * @date 2019-07-31
 */
@Slf4j
@Service
public class UserServiceImpl1 {


    @Autowired
    UserDao userDao;
    public UserEntity getUser(Long id){
        return  userDao.getUser(id);
    }


    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)
    public List<UserEntity> getUsers() {
        List<Long> ids=new ArrayList<>();
        ids.add(1L);
        ids.add(2L);
        ids.add(3L);
        List<UserEntity> userEntities = new ArrayList<>();
        for (Long id : ids) {
            UserEntity user = userDao.getUser(id);
            userEntities.add(user);
        }
        return userEntities;
    }
}
